package com.homedo.odin.solution.controller.pc;

import com.homedo.core.common.base.controller.BaseController;
import com.homedo.core.common.base.dto.Meta;
import com.homedo.core.common.base.dto.ResultData;
import com.homedo.odin.solution.contract.pc.AdoptReplyReq;
import com.homedo.odin.solution.contract.pc.BountyMenResp;
import com.homedo.odin.solution.contract.pc.CloseBountyReq;
import com.homedo.odin.solution.contract.pc.GetBountyByIdResp;
import com.homedo.odin.solution.contract.pc.GetBountyListReq;
import com.homedo.odin.solution.contract.pc.GetBountyListResp;
import com.homedo.odin.solution.contract.pc.HebiResp;
import com.homedo.odin.solution.contract.pc.HighMoneyBountysResp;
import com.homedo.odin.solution.contract.pc.InsertBountyReq;
import com.homedo.odin.solution.contract.pc.InsertBountyResp;
import com.homedo.odin.solution.service.bizservice.personal.BountyBizService;
import com.homedo.odin.solution.service.bizservice.personal.BountyTotalBizService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: donglibing
 * @date: 2018/3/6 14:39
 * @Description:
 */
@Api(description = "悬赏", tags = {"Bounty"}, produces = MediaType.APPLICATION_JSON_VALUE)
@RestController
@RequestMapping("/personal")
public class BountyController extends BaseController<BountyBizService> {


    @Autowired
    BountyTotalBizService bountyTotalBizService;

    @ApiOperation(value = "获取悬赏列表", notes = "获取悬赏列表", response = GetBountyListResp.class, httpMethod = "GET")
    @GetMapping("/bounty/list")
    public ResultData list(@ModelAttribute("request") GetBountyListReq request) {
        GetBountyListResp resp = baseService.getBountyList(request);
        return ResultData.newInstance(Meta.CODE_200, resp);
    }

    @ApiOperation(value = "发布悬赏", notes = "发布悬赏", response = InsertBountyResp.class, httpMethod = "POST")
    @PostMapping("/bounty/publish")
    public ResultData insert(@RequestBody InsertBountyReq req) {
        InsertBountyResp resp = new InsertBountyResp();
        int reslut = baseService.publish(req);
        resp.setId(reslut);
        return ResultData.newInstance(Meta.CODE_200, resp);
    }

    @ApiOperation(value = "获取高赏金悬赏列表", notes = "获取高赏金悬赏列表", response = HighMoneyBountysResp.class, httpMethod = "GET")
    @GetMapping("/bounty/highmoneybountys/{top}")
    public ResultData highMoneyBountys(@ApiParam(value = "top", required = true) @PathVariable("top") int top) {

        HighMoneyBountysResp resp = baseService.highMoneyBountys(top);
        return ResultData.newInstance(Meta.CODE_200, resp);
    }

    @ApiOperation(value = "获取悬赏达人列表", notes = "获取悬赏达人列表", response = BountyMenResp.class, httpMethod = "GET")
    @GetMapping("/bounty/bountymen/{top}")
    public ResultData bountyMen(@ApiParam(value = "top", required = true) @PathVariable("top") int top) {

        BountyMenResp resp = bountyTotalBizService.getBountyMen(top);
        return ResultData.newInstance(Meta.CODE_200, resp);
    }

    @ApiOperation(value = "根据id查看悬赏", notes = "根据id查看悬赏", response = GetBountyByIdResp.class, httpMethod = "GET")
    @GetMapping("/bounty/checkbounty/{id}")
    public ResultData checkBounty(@ApiParam(value = "悬赏id", required = true) @PathVariable("id") int id) {
        GetBountyByIdResp resp = baseService.checkBounty(id);
        return ResultData.newInstance(Meta.CODE_200, resp);

    }

    @ApiOperation(value = "关闭任务", notes = "关闭任务")
    @PutMapping("/bounty/close")
    public ResultData close(@RequestBody CloseBountyReq req) {
        baseService.close(req);
        return ResultData.newInstance(Meta.CODE_200, "关闭任务成功");
    }

    @ApiOperation(value = "采纳答案", notes = "采纳答案")
    @PutMapping("/bounty/useIt")
    public ResultData useIt(@RequestBody AdoptReplyReq req) {
        baseService.adopt(req);
        return ResultData.newInstance(Meta.CODE_200, "采纳答案成功");
    }


    @ApiOperation(value = "查询我的河币", notes = "查询我的河币", response = HebiResp.class, httpMethod = "GET")
    @GetMapping("/bounty/gethebi/{id}")
    public ResultData getHebi(@ApiParam(value = "用户ID", required = true) @PathVariable("id") int id) {
        HebiResp resp = baseService.getHebi(id);
        return ResultData.newInstance(Meta.CODE_200, resp);

    }

}
